<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表盘资源</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            background-color: #181818;
            font-weight: 300;
            color: white;
        }
        .container {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            padding: 60px 20px 0px 20px;
        }

        .box {
            /* margin: 1%; */
            width: 280px;
            height: 350px;
            background: rgb(40, 40, 40);
            margin-top: 30px;
            padding: 10px;
            margin: 10px;
        }

        .header {
            position: fixed;
            width: 100%;
            background: rgb(30, 30, 30);
            height: 50px;
            line-height: 50px;
            font-size: 8px;
            padding-left: 30px;
        }
    </style>

    <style>
        .box_header {
            width: auto;
            font-size: 8px;
            font-size: 10px;
            transform: scale(0.8);
            transform-origin: 0% 0%;
            padding: 3px;
            margin: 2px;
        }

        .box_header_box {
            background: #31456a;
            color: #00cad6;
            border-radius: 5px;
            padding: 4px;

        }

        img {
            width: 130px;
            height: 240px;
            display: block;
            margin: 0 auto;
            overflow: hidden;
            border-radius: 5px;
        }

        img:hover,
        .box_header_box:hover {
            opacity: 0.7;
        }
        .block_text {
            text-align: center;
            margin: 10px;
            margin-top: 20px;
            
        }

        .fa-home {
            font-size: 13px;
        }

        .author {
            transform: scale(0.8);
            font-size: 0.8rem;
            color: rgb(200, 160, 40);
            cursor: pointer;
        }

        #template {
            display: inline;
        }
    </style>


</head>

<body>
    <div class="header">
        <h1>表盘资源站</h1>
    </div>

    <div class="container">
        <template id="template-task">
            <div class="box">
                <div class="box_header">
                    <span class="box_header_box">Band 6</span>
                </div>
                <img src="./resource/everest.jpg" alt="">
                <div class="block_text" src="./resource/applewatch.hwt">
                    <i class="fa fa-home"></i>
                    <span class="author">作者</span>
                </div>
            </div>
        </template>
    </div>
    <script>
        
    </script>
    <script>

        let data = [{
            band: "Band 6",
            resource: "applewatch",
            author: "applewatch",
        }, {
            band: "Band 6",
            resource: "everest",
            author: "everest"
        },{
            band: "Band 6",
            resource: "futuristicanalog",
            author: "futuristicanalog"
        },{
            band: "Band 6",
            resource: "nikegrey",
            author: "nikegrey"
        },{
            band: "Band 6",
            resource: "gtsv4",
            author: "gtsv4"
        },{
            band: "Band 6",
            resource: "md",
            author: "md"
        },{
            band: "Band 6",
            resource: "nike_active_2.1.1",
            author: "nike_active_2.1.1"
        },{
            band: "Band 6",
            resource: "spaceman",
            author: "spaceman"
        },{
            band: "Band 6",
            resource: "glowingblue",
            author: "glowingblue"
        },{
            band: "Band 6",
            resource: "ios29",
            author: "ios29"
        },{
            band: "Band 6",
            resource: "apwsportslsd_en_2.1.1",
            author: "apwsportslsd_en_2.1.1"
        },
        {
            band: "Band 6",
            resource: "royalclassic",
            author: "royalclassic"
        },
        {
            band: "Band 6",
            resource: "turbocharged",
            author: "turbocharged"
        },{
            band: "Band 6",
            resource: "gtsv4",
            author: "gtsv4"
        },{
            band: "Band 6",
            resource: "nikehwhite",
            author: "nikehwhite"
        }]
        const taskTemplate = document.querySelector('#template-task');
        let domArray = []
        for (let i of data) {
            let taskDOM = taskTemplate.content.firstElementChild.cloneNode(true);
            taskDOM.querySelector(".box_header_box").innerHTML = i.band
            taskDOM.querySelector("img").setAttribute("src",`./resource/${i.resource}.jpg`) 
            taskDOM.querySelector(".block_text").setAttribute("src",`./resource/${i.resource}.hwt`) 
            taskDOM.querySelector(".author").innerHTML = i.author;
            document.querySelector(".container").append(taskDOM)
        }
        document.querySelectorAll(".block_text").forEach((v)=>{
            v.addEventListener("click",(e)=>{
                let src =v.getAttribute("src")
                const alink = document.createElement('a');
                console.log(src)
                alink.href = `${src}`
                alink.download = src.split("/").at(-1)
                alink.style.display = "none";
                alink.click();
                alink.remove()
            },false)
        })


    </script>
</body>

</html>